import { InjectModel } from '@nestjs/mongoose'
import { WebSocketGateway, SubscribeMessage, MessageBody } from '@nestjs/websockets'
import { Model } from 'mongoose'
import { Chat, chatDocument } from '../model/chat.schema'
import { ChattingType } from './dto/chat.dto'

@WebSocketGateway(3002)
export class WsGateway {
  constructor(@InjectModel(Chat.name) private chatSchema: Model<chatDocument>) {}
  /* 获取消息记录 */
  async getRecord(send: string, receive: string) {}

  @SubscribeMessage('send')
  async chat(@MessageBody() data: ChattingType) {
    const result = await this.chatSchema.create(data)
    return { code: 200, result }
  }
}
